<!--
描述：面试题审核信息组件
开发人：zyanming
开发日期：2018年9月13日
修改人：hqj
修改日期：2018年10月17日
-->
<template lang="pug">
    keep-alive(v-if="pageShow")
        kalix-table(bizKey="interviewIssueCheck" v-bind:title="title1" v-bind:targetURL="targetURL"
        v-bind:bizDialog="bizDialog" v-bind:btnList="btnList" v-bind:dictDefine="dictDefine"
        v-bind:toolbarBtnList="toolbarBtnList" v-bind:customToolBar="customToolBar" v-bind:customTableTool="customTableTool"
        v-bind:isFixedColumn="isFixedColumn" v-on:afterDialogClose="dialogClose"
        v-bind:attachmentReadOnly="true" v-bind:getDateCallback="getDateCallback" ref="kalixTable")
            template(slot="tableColumnSlot")
                el-table-column(prop="checkFlag" label="审核状态" align="center" width="120px")
                    template(slot-scope="scope")
                        template(v-if="scope.row.checkFlag === '1'")
                            el-tag(type="success") 已通过
                        template(v-else-if="scope.row.checkFlag === '2'")
                            el-popover(trigger="hover" placement="top" width="120")
                                | 审核未通过原因
                                br
                                | {{scope.row.checkReason}}
                                div(slot="reference")
                                    el-tag(type="danger") 未通过
                        template(v-else)
                            el-tag 未审核
                el-table-column(prop="subTypeName" label="面试题类型" align="center" width="150px")
                kalix-date-column(prop="year" label="年份" align="center" width="150px")
                el-table-column(prop="id" label="ID" align="center" width="150px")
                el-table-column(prop="stem" label="题干" align="center" width="350px")
                    template(slot-scope="scope")
                        el-popover(trigger="hover" placement="top" width="350")
                            | {{scope.row.stem}}
                            div(slot="reference")
                                template(v-if="scope.row.stem && scope.row.stem.length > 20")
                                    | {{scope.row.stem.substr(0, 20)}}...
                                template(v-else)
                                    | {{scope.row.stem}}
                el-table-column(prop="analysis" label="试题解析" align="center" width="350px")
                    template(slot-scope="scope")
                        el-popover(trigger="hover" placement="top" width="350")
                            | {{scope.row.analysis}}
                            div(slot="reference")
                                template(v-if="scope.row.analysis && scope.row.analysis.length > 20")
                                    | {{scope.row.analysis.substr(0, 20)}}...
                                template(v-else)
                                    | {{scope.row.analysis}}
                el-table-column(prop="scoreStandard" label="评分标准" align="center" width="350px")
                    template(slot-scope="scope")
                        el-popover(trigger="hover" placement="top" width="350")
                            | {{scope.row.scoreStandard}}
                            div(slot="reference")
                                template(v-if="scope.row.scoreStandard && scope.row.scoreStandard.length > 20")
                                    | {{scope.row.scoreStandard.substr(0, 20)}}...
                                template(v-else)
                                    | {{scope.row.scoreStandard}}
                el-table-column(prop="checker" label="审核员" align="center" width="120px")
                el-table-column(prop="checkDate" label="审核时间" align="center" width="180px")
                    template(slot-scope="scope")
                        i(class="el-icon-time")
                        span {{scope.row.checkDate}}
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import ProgressFormModel from './progressModel'
    import {CheckProgressURL, InterviewIssueCheckURL, QuestionPreviewURL} from '../../../config.toml'
    import {questionCheckBtnList, questionCheckBtnList2} from '../../config.js'
    import {availableQuestion} from '../../../common.js'

    export default {
        name: 'kalix-enrolment-interviewissuecheck',
        props: {
            title: {
                type: String,
                default: ''
            },
            subType: {
                type: String,
                required: true
            },
            useAttachment: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                pageShow: false,
                progressFormModel: Object.assign({}, ProgressFormModel),
                dictDefine: [{
                    cacheKey: 'ENROLMENT-DICT-KEY',
                    type: '面试题类型',
                    targetField: 'subTypeName',
                    sourceField: 'subType'
                }],
                btnList: this.useAttachment ? questionCheckBtnList2 : questionCheckBtnList,
                toolbarBtnList: [
                    /*{id: 'batchAudit', title: '批量审核', isShow: true, icon: 'icon-add'},*/
                    {id: 'add', isShow: false}
                ],
                targetURL: InterviewIssueCheckURL + '?subType=' + this.subType,
                bizDialog: [
                    {id: 'view', dialog: 'InterviewIssueCheckView'},
                    /*{id: 'audit', dialog: 'InterviewIssueCheckAudit'}*/
                    {id: 'noPass', dialog: 'InterviewIssueCheckAudit'}
                ],
                isFixedColumn: true
            }
        },
        components: {},
        created() {
            availableQuestion(this.axios, this.$KalixMessage, flag => {
                this.pageShow = flag
            })
        },
        activated() {
        },
        deactivated() {
        },
        computed: {
            title1() {
                return this.title + ' － ' + this.progressFormModel.auditorNum + '人审核，你已审核' + this.progressFormModel.completeNum +
                    '道试题，共需要审核' + this.progressFormModel.questionNum + '道试题，已完成' + this.progressFormModel.completeTotal + '道试题'
            }
        },
        methods: {
            customToolBar(btnId, table) {
                switch (btnId) {
                    /*case 'batchAudit': {
                        this.onBatchAudit(null, table)
                        break
                    }*/
                }
            },
            customTableTool(row, btnId, that) {
                switch (btnId) {
                    case 'preview': { // 预览
                        window.open(this.$KalixGlobalConfig.baseURL + QuestionPreviewURL
                            + '&beanname=InterviewIssue&id=' + row.id + '&access_token=' + this.$KalixCatch.get('access_token'))
                        break
                    }
                    /*case 'audit': {
                        this.onBatchAudit(row, that)
                        break
                    }*/
                    case 'pass': {
                        let warnInfo = '确定要通过吗？'
                        that.$confirm(warnInfo, '警告', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(() => {
                            return this.axios.request({
                                method: 'PUT',
                                url: this.targetURL,
                                params: {
                                    entityIds: row.id.toString(),
                                    checkFlag: '1',
                                    reason: ''
                                },
                                data: {}
                            })
                        }).then(response => {
                            this.$KalixMessage.processResult(response)
                            this.$KalixEventBus.$emit(this.$KalixEventConfig.ON_REFRESH_DATA)
                        }).catch((e) => {
                        })
                        break
                    }
                    case 'noPass': {
                        this.onBatchAudit(row, that)
                        break
                    }
                }
            },
            onBatchAudit(row, table) {
                if (row) {
                    let dig =
                        table.bizDialog.filter((item) => {
                            return item.id === 'noPass'
                        })
                    table.whichBizDialog = dig[0].dialog
                    setTimeout(() => {
                        table.$refs.kalixDialog.$refs.kalixBizDialog.open('审核', false, row)
                    }, 20)
                } else {
                    alert('null')
                }
            },
            dialogClose() {
                this.$refs.kalixTable.refresh()
            },
            getDateCallback(queryParams) {
                this.axios.request({
                    method: 'GET',
                    url: CheckProgressURL.replace('[beans]', 'interviewissues'),
                    params: {'jsonStr': {"subType": this.subType}}
                }).then(response => {
                    if (response.data) {
                        this.progressFormModel = response.data
                    }
                }).catch((e) => {
                })
            }
        }
    }
</script>

<style scoped lang="stylus">
</style>
